<template>
  <!-- 信用表 -->
  <div class="app-container">


    <el-form ref="form" :model="form" :rules="rules" label-width="200px" v-loading="loading" >
      <el-form-item label="患 者：" prop="idcard">
        <el-select
          v-model="form.idcard"
          placeholder="请选择患者"
        >
          <el-option v-for="item in selectList"
                     :key="item.idcard"
                     :label="item.recorder"
                     :value="item.idcard"
          />
        </el-select>
        <el-button type="primary" @click="submitForm" style="margin-left: 20px">确 定</el-button>
      </el-form-item>
    </el-form>
    <div class="creditBox" v-show="userInfo.idcard">
      <div class="leftBox">
        <div class="chart-wrapper">
          <pie-chart ref="pieEl"/>
        </div>
        <div class="bigNum"><p>{{ userInfo.finalScore }}</p>最终信用评分</div>
      </div>
      <div class="rightBox">
        <div class="panel" style="height: 150px">
          <div class="headerBox"><img src="../../../assets/images/icon1.png"/></div>
          <div class="name">
            <div class="line" style="font-size: 18px">患者身份证号：{{ userInfo.idcard }}</div>
            <div class="line"

            >
              <p>查询人：{{ userInfo.queriedBy }}</p>
              <p>查询时间：{{ userInfo.queryTime }}</p>

            </div>
          </div>
        </div>
        <div class="panel" style="height: 310px;margin-top: 18px">
          <div class="panelBox">
            <div class="line">明细类型：{{ userInfo.detailType }}</div>
            <div class="line">明细描述：{{ userInfo.detailDescription }}</div>
            <div class="line">明细评分：{{ userInfo.detailScore }}</div>
          </div>


        </div>
      </div>
    </div>

  </div>
</template>

<script>
import { searchCredit, selectPatient } from '@/api/credit/creditTable'
import PieChart from './PieChart'

export default {
  components: { PieChart },
  name: 'patient',
  dicts: [],
  data() {
    return {
      // 遮罩层
      loading: false,
      form: {},
      userInfo: {
        'idcard': null,
        'queryTime': null,
        'queriedBy': null,
        'insuranceScore': null,
        'identityScore': null,
        'recordScore': null,
        'staffScore': null,
        'blacklistScore': null,
        'finalScore': null,
        'detailType': null,
        'detailDescription': null,
        'detailScore': null
      },
      selectList: [],
      // 表单校验
      rules: {
        idcard: [
          { required: true, message: '请选择患者', trigger: 'blur' }
        ]
      }

    }
  },
  created() {
    this.selectPatient()
  },
  methods: {
    /** 查询用户列表 */
    getList() {
      this.loading = true
      searchCredit(this.form).then(response => {
          // console.log('response',response)
          this.loading = false
          if (!response.data) {
            this.$modal.msg(response.msg)
            return

          }

          this.userInfo = {
            'idcard': response.data.idcard,
            'queryTime': response.data.queryTime,
            'queriedBy': response.data.queriedBy,
            'insuranceScore': response.data.insuranceScore,
            'identityScore': response.data.identityScore,
            'recordScore': response.data.recordScore,
            'staffScore': response.data.staffScore,
            'blacklistScore': response.data.blacklistScore,
            'finalScore': response.data.finalScore,
            'detailType': response.data.detailType,
            'detailDescription': response.data.detailDescription,
            'detailScore': response.data.detailScore
          }
          console.log('this.$refs.pieEl', this.$refs.pieEl)
          setTimeout(() => {
            this.$refs.pieEl.initChart([
                    { value: this.userInfo.insuranceScore, name: '医保信息评分' },
                    { value: this.userInfo.identityScore, name: '患者身份评分' },
                    { value: this.userInfo.recordScore, name: '就诊记录评分' },
                    { value: this.userInfo.staffScore, name: '医护人员主观评分' },
                    { value: this.userInfo.blacklistScore, name: '黑名单评分' }
              ]
            )
          }, 200)

          this.loading = false
        }
      )
    },

    //查询患者
    selectPatient() {
      selectPatient({}).then(response => {
          this.selectList = response.rows

        }
      )
    },
    submitForm: function() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          this.getList()

        }
      })
    }

  }
}
</script>
<style scoped>
.creditBox {
  display: flex;
  justify-content: space-around; /* 水平方向间隔分布 */
  gap: 20px; /* 设置间隔为20px */
  height: 480px;
  padding-bottom: 50px;
  box-sizing: content-box;
}

.leftBox {
  height: 100%;
  flex: 3;
  background: #e7effc;
  border: solid 1px #afceff;
  /*box-shadow: 0 0 5px #eee;*/
}

.rightBox {
  height: 100%;
  flex: 4;

  /*box-shadow: 0 0 5px #eee;*/
}

.chart-wrapper {
  width: 100%;
  padding: 15px 15px 0;
  margin-bottom: 20px;
  box-sizing: border-box;
}

.bigNum {
  font-size: 18px;
  text-align: center;
  color: #333;
  margin-top: -20px;
}

.bigNum p {
  font-weight: 600;
  font-size: 52px;
  color: #5c78ff;
}

.panel {
  position: relative;
  background: #e7effc;
  border: solid 1px #afceff;
  width: 100%;
}

.headerBox {
  width: 110px;
  height: 110px;
  margin: 20px 0 0 30px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.8);
  border: solid 1px #afceff;
  padding: 10px;
  box-sizing: border-box;
}

.headerBox img {
  width: 100%;
  height: 100%;
}

.name {
  position: absolute;
  top: 30px;
  left: 160px;

  width: calc(100% - 200px);


}

.line {
  display: flex;
  justify-content: space-between;
  width: 100%;
  font-size: 16px;
  line-height: 40px;
  color: #333;

}

.panelBox {
  padding: 20px;
}

.panelBox .line {
  margin-bottom: 10px;
}
</style>
